package com.intro.database.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.CollectionOfElements;

//新闻实体类
@Entity
@Table(name = "News", catalog = "intro")
public class News implements Serializable {

	public static final int TYPE_NEWS = 1;
	public static final int TYPE_PROJECT = 0;

	@GeneratedValue
	private int id;// id

	private String title;// 标题
	@Column(name = "content", length = 2500)
	private String content;// 内容

	private String imagePath;// 图片路径

	private Date date;// 存储日期

	private int type = 1;// 类型 1表示新闻 0表示项目

	private List<Image> images = new ArrayList<Image>();// 图片集合

	public Date getDate() {
		return date;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	@Column(name = "title", length = 500)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "content", length = 2500)
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

/*	@CollectionOfElements()
	@JoinTable(name = "images", joinColumns ={ @JoinColumn(name = "news_ID") })
	@Column(name = "filename", nullable = true)
	集合映射时使用
*/
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "news_id")
	public List<Image> getImages() {
		return images;
	}

	public void setImages(List<Image> images) {
		this.images = images;
	}

}
